package cn.com.recode.e继承;

public class Movie {

    public static final int CHILDRENS = 2;

    public static final int REGULAR = 0;

    public static final int NEW_RELEASE = 1;

    private String _title;

    private Price price;

    public Movie(String title, int priceCode) {
        this._title = title;
        setPriceCode(priceCode);
    }

    public String getTitle() {
        return _title;
    }

    public void setTitle(String title) {
        this._title = title;
    }

    public int getPriceCode() {
        return price.getPriceCode();
    }

    /**
     * 使用state模式来构建，好处:修改任何与价格相关的行为时,程序修改方便得多
     * @param priceCode
     */
    public void setPriceCode(int priceCode) {
        switch(priceCode){
            case REGULAR:
                price = new RegularPrice();
                break;
            case NEW_RELEASE:
                price = new NewReleasePrice();
                break;
            case CHILDRENS:
                price = new ChildrenPrice();
                break;
            default:
                throw new IllegalArgumentException("wrong price code");

        }
    }




    /**
     * 对于对象属性的操作,最好放在对象内部
     * @param daysRented
     * @return
     */
    public double getFrenquentRenterPoints(int daysRented) {
        return price.getFrenquentRenterPoints(daysRented);
    }

    public double getCharge(int daysRented) {
        return price.getCharge(daysRented);
    }
}
